//
//  ArrayController.m
//  <6.2>RaiseMan(代码)
//
//  Created by chen on 16/9/8.
//  Copyright © 2016年 tyrad. All rights reserved.
//

#import "ArrayController.h"
#import "Person.h"
 
@implementation ArrayController

- (NSMutableArray<Person *> *)employees{
    if (_employees == nil) {
        _employees = @[].mutableCopy ;
    }
    return _employees ;
}


- (IBAction)add:(id)sender {
    
    Person *p = [[Person alloc]init]; //self	Document *	0x6080000e3380	0x00006080000e3380
    
    [self.employees addObject:p];
    
    
    [_tableView reloadData];
}


- (IBAction)delete:(id)sender {
    
    NSIndexSet *rows = [self.tableView selectedRowIndexes];
    
    if (rows.count == 0 ) {
        
        NSBeep();
        
    }else {
        
        [_employees removeObjectsAtIndexes:rows];
        [self.tableView reloadData];
    }
}

#pragma mark -- tableView

- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView{
    
    NSLog(@",,,%@",(self.employees)) ; //self	Document *	0x6000000e2280	0x00006000000e2280
    
    return self.employees.count;
}

-   (nullable id)tableView:(NSTableView *)tableView
 objectValueForTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger)row{
    
    Person *p = _employees[row] ;
    
    NSLog(@"```%@", tableColumn.identifier);
    
    return [p valueForKey:tableColumn.identifier] ;
}

- (void)tableView:(NSTableView *)tableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row{
    
    //手动改值后
    
    NSString *ide = tableColumn.identifier ;
    
    Person * p = _employees[row] ;
    
    [p setValue:object forKey:ide];
    
    
}



@end































